package ebj.common.httpclient;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import com.google.gson.Gson;

import ebj.common.httpclient.bean4test.Query;

public class RequestTest {

    static String urlString = "http://127.0.0.1:8080/datasystem-realquery/report?report_param={%22settings%22:{%22report_id%22:%228412b4adf34ae00d9559e212c72ce57c%22,%22return_format%22:%22json%22,%22data_source%22:%22ymds_druid_datasource%22,%22time%22:{%22start%22:1401321600,%22end%22:1401408000,%22timezone%22:0},%22pagination%22:{%22size%22:50,%22page%22:0}},%22group%22:[%22click_time%22,%22conv_time%22,%22time_diff%22,%22aff_id%22,%22aff_sub1%22,%22offer_id%22,%22transaction_id%22,%22country%22,%22conv_ip%22,%22click_ip%22],%22data%22:[%22cr%22],%22filters%22:{%22$and%22:{%22aff_manager%22:{%22$in%22:[%2231%22]}}}}";
    static String uri = "http://127.0.0.1:8080/datasystem-realquery/report";
    static String parameter = "{\"settings\":{\"report_id\":\"8412b4adf34ae00d9559e212c72ce57c\",\"return_format\":\"json\",\"data_source\":\"ymds_druid_datasource\",\"time\":{\"start\":1401321600,\"end\":1401408000,\"timezone\":0},\"pagination\":{\"size\":50,\"page\":0}},\"group\":[\"click_time\",\"conv_time\",\"time_diff\",\"aff_id\",\"aff_sub1\",\"offer_id\",\"transaction_id\",\"country\",\"conv_ip\",\"click_ip\"],\"data\":[\"cr\"],\"filters\":{\"$and\":{\"aff_manager\":{\"$in\":[\"31\"]}}}}";
    static String url2 = "http://127.0.0.1:8080/datasystem-realquery/report?report_param={\"settings\":{\"report_id\":\"8412b4adf34ae00d9559e212c72ce57c\",\"return_format\":\"json\",\"data_source\":\"ymds_druid_datasource\",\"time\":{\"start\":1401321600,\"end\":1401408000,\"timezone\":0},\"pagination\":{\"size\":50,\"page\":0}},\"group\":[\"click_time\",\"conv_time\",\"time_diff\",\"aff_id\",\"aff_sub1\",\"offer_id\",\"transaction_id\",\"country\",\"conv_ip\",\"click_ip\"],\"data\":[\"cr\"],\"filters\":{\"$and\":{\"aff_manager\":{\"$in\":[\"31\"]}}}}";
    
    public static void main(String[] args) throws UnsupportedEncodingException, HttpException {
        String tmp = URLDecoder.decode(urlString, "UTF-8");
//        System.out.println(tmp.charAt(63));
        // System.out.println(NetService.yeahmobiCallBack(URLDecoder.decode(urlString, "UTF-8")));
        // System.out.println(NetService.yeahmobiCallBack(tmp));
//        System.out.println(NetService.yeahmobiCallBack2(uri, parameter));
        
        Query query = new Query();
        query.setDatasource(1);
        query.setQueryName("ab-test");
        query.setQueryStr("select * from tabl-a;");
        query.setUserId(12333);
//        String json_param = new Gson().toJson(query);
        String json_param = "{\"execMode\":\"HIVE\",\"roleName\":\"role_name\",\"sql\":\"select * from dw_fltdb.es_demo_tbl limit 3;\",\"userId\":\"2\",\"rowLimit\":100000,\"queryId\":\"8243ce0b-beea-404f-b938-400283a2501b\",\"offset\":\"1200\",\"limit\":\"limit\"}";
        
//        APIHttpClient client = new APIHttpClient("http://localhost:8080/adhoc-platform/api/query/submit.json");
//        
//        String result = client.post(json_param);
//        System.out.println("result -->> " + result);
        String url = "http://10.2.26.60:8080/adhoc-query-service/submit";
//        String url = "http://localhost:8080/adhoc-platform/api/user/info/1.json";
        StringEntity entity = new StringEntity(
				json_param,
				ContentType.create("application/json", "UTF-8"));
        String post_req_result = Http.post(url, entity);
//        String post_req_result = Http.get(url);
        System.out.println(post_req_result);
    }
}
